package com.palnar.ilecker.manager.db;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

import android.content.Context;
import android.database.Cursor;
import android.util.Log;

import com.palnar.ilecker.constants.IDBConstants;

public class DataBaseManager implements IDBConstants{
	
	
	private Context mContext;
	private SQLiteAdapter mySQLiteAdapter;

	/**
	 * Instantiates a new database manager.
	 *
	 * @param context the context
	 */
	public DataBaseManager(Context context) {
		mContext = context;
	}

	public boolean deleteGroup(Context context, String tblName,String cons)
	{
		int i=-1;
		mySQLiteAdapter = new SQLiteAdapter(context);
		mySQLiteAdapter.openToWrite(DB_NAME);
		i = mySQLiteAdapter.makeEmpty(tblName, cons);
		mySQLiteAdapter.close();
		if(i>0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	public boolean deleteRows(Context context, String tblName, String cons)
	{
		int i=-1;
		mySQLiteAdapter = new SQLiteAdapter(context);
		mySQLiteAdapter.openToWrite(DB_NAME);
		i = mySQLiteAdapter.makeEmpty(tblName, cons);
		
		mySQLiteAdapter.close();
		if(i>0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	/*public boolean createGroup(Context context, String tblName,String [] [] data,ArrayList<FriendsModel> arrayList)
	{
		long i;
		boolean isSuccess=false;
		mySQLiteAdapter = new SQLiteAdapter(context);
		mySQLiteAdapter.openToWrite(DB_NAME);
		i = mySQLiteAdapter.insertWithID(data, tblName);
		if(i!=-1)
		{
			for (int j = 0; j < arrayList.size(); j++)
			{
				String[][] data1 = { { TBL_MEMBERS_GROUP_ID, String.valueOf(i) },
						{ TBL_MEMBERS_CONTACT_ID,arrayList.get(j).getContactId() },
						{TBL_MEMBERS_FRIEND_ID ,arrayList.get(j).getId()}
			 		  };
				isSuccess= addMembers(context, TBL_MEMBERS,data1);
			}
			return isSuccess;
		}
		else
		{
			return false;
		}
		
	}*/
	public boolean addMembers(Context context,String tblName,String [] [] datas)
	{
		mySQLiteAdapter = new SQLiteAdapter(context);
		mySQLiteAdapter.openToWrite(DB_NAME);
		return mySQLiteAdapter.insert(datas, tblName);
	}
	
	public void editGroup(Context context, String tblName,String [] [] content,String [] [] whereClause)
	{
		mySQLiteAdapter = new SQLiteAdapter(context);
		mySQLiteAdapter.openToWrite(DB_NAME);
		mySQLiteAdapter.update(content, tblName, whereClause);
		mySQLiteAdapter.close();
	}

}
